﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using bdtheque.data.interfaces;

namespace bdtheque.data.dataaccess
{
    public sealed class BdthequeUnitOfWorkFactory : IUnitOfWorkFactory
    {
        // Singleton Implementation
        private BdthequeUnitOfWorkFactory() { }

        // Singleton Implementation
        public static BdthequeUnitOfWorkFactory GetInstance
        {
            get { return BdthequeUnitOfWorkFactoryImpl.instance; }
        }

        public static string ConnectionString
        {
            get; set;
        }

        // Factory Method
        public IUnitOfWork Create(string connectionString)
        {
            if (connectionString == null)
                throw new ArgumentNullException("ConnectionString");

            return new BdthequeUnitOfWork(connectionString);
        }

        // Factory Method
        public IUnitOfWork Create()
        {
            if (ConnectionString == null)
                throw new ArgumentNullException("ConnectionString");

            return new BdthequeUnitOfWork(ConnectionString);
        }

        // Singleton Implementation
        private class BdthequeUnitOfWorkFactoryImpl
        {
            internal static readonly BdthequeUnitOfWorkFactory instance = new BdthequeUnitOfWorkFactory();

            static BdthequeUnitOfWorkFactoryImpl() { }
        }
    }
}
